package cn.zniot.so.application;

import java.net.MalformedURLException;
import java.rmi.RemoteException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import cn.zniot.so.application.constant.Constants;
import cn.zniot.so.application.service.ServiceManager;
import cn.zniot.so.application.util.LoadConf;
import cn.zniot.so.database.ConnectionMgr;
import cn.zniot.so.transport.CommonManager;


/**
 * zniot模块启动入口
 */
public class Entrance {

	private static final Log logger = LogFactory.getLog(Entrance.class);


	public static void main(String[] args)
	{
		LoadConf.init(Constants.HOME_DIR);// 加载配置文件
		try
		{
			start();
		} catch (Exception e)
		{
			logger.error("start error system will quit with code -333\r\n", e);
			System.exit(-33);
		}
	} 
	
	/**
	 * 启动服务
	 * @throws MalformedURLException 
	 * @throws RemoteException 
	 * @throws Exception 
	 */
	private static void start() throws MalformedURLException,Exception, RemoteException {

		// 初始化数据库连接
		ConnectionMgr.getInstance().initDB();

		// 启动发布服务
		ServiceManager.getInstance().startUpService();

		// 启动box监听服务器
		CommonManager.getInstance().startUpBox();
		
		//启动客户端访问服务器httpserver
		CommonManager.getInstance().startUpHttp();
		
		// 启动命令执行监听器
//		CommonManager.getInstance().startUpFurnishingTcp();
		
		//启动文件上传服务器
		CommonManager.getInstance().startUpFileUpload();
	}
	
}
